//Triangle program - input of 3 side lengths output of whether the triangle is equilateral, scaleen, isoceles
//January 2012 for SSW 570 Software Testing

public class triangle 
{
	public static void main(String[] args)
    {

	   //safety - check args
	   if(args.length < 3)
	   {
	       System.out.println("Not enough args - 3 lengths needed.");
		   return;
	   }
	   if(args.length >= 4)
	   {
	       System.out.println("Too many arguments. 3 lengths needed.");
		   return;
       }

	   //get 3 arguments
	   double len1 = 0.0;
	   double len2 = 0.0;
	   double len3 = 0.0;
	   try {
	      len1 = Double.valueOf(args[0]).doubleValue(); //unlike C Java's 0 arg is not program name.
	      len2 = Double.valueOf(args[1]).doubleValue();
	      len3 = Double.valueOf(args[2]).doubleValue();
		} catch (NumberFormatException e)
		{
			System.out.println("Invalid arguments - letter detected.");
			return;
		}
		
		// Does the Triangle Exist?
		if( (len1 <= 0) || (len2 <= 0) || (len3 <= 0) )
		{
		   System.out.println("Negative or zero value found, aborting.\n");
		   return;
		}
		if( ((len1+len2) <= len3) || ((len1+len3) <= len2) || ((len2+len3) <= len1) )
		{
			System.out.println("Side lengths invalid, side too large. Not a triangle.\n");
			return;
		}
		
	   //is triangle equilateral?
	   if(len1 == len2 && len2 == len3)
		  System.out.println("Equilateral");
       else
	   {
		  if (len1 == len2 || len2 == len3 || len1 == len3)
	      {
	         //Isosceles?
		     System.out.println("Isosceles");
	      }
	      else
	      {
	         //Then it must be scaleen
	         System.out.println("All sides unique - scaleen");
          }
	   }

	   //overflow detection and handling section
	   
	   //find largest value
	   double largest = len1;
	   double smaller = len2;
	   
	   if(len1 >= len2 && len1 >= len3)
	   {
	      largest = len1;
		  smaller = len2;
	   }
	   else 
	      if(len2 >= len3)
		  {
	         largest = len2;
			 smaller = len3;
		  }
	      else
		  {
	         largest = len3;
			 smaller = len1;
		  }
		  
		if( ((largest*largest) / largest) == largest )
		{
		   //The value first overflows during multiplication... so if the value
		   // is not equal to itself after some mathematics, there was an overflow.
		   len1 = len1 / 1000000;
		   len2 = len2 / 1000000;
		   len3 = len3 / 1000000;
		   System.out.println("Overflow found ");
		}
	    
	   
	   //end overflow detection section
	   
	   //Right angled? (A^2 + B^2 = C^2)
	   double a = len1*len1;
	   double b = len2*len2;
       double c = len3*len3;
	   
	   //Round nearest whole number to account for square roots etc
	   //System.out.println( (Math.round(a+b)) );
	   
	   if( (Math.round(a+b)) == Math.round(c) )
		  System.out.println("Right angle" + c + " " + a + " " + b);
	   if( (Math.round(b + c)) == Math.round(a) )
		  System.out.println("Right angle");
	   if( ( (Math.round(a + c)) == Math.round(b) ) )
		  System.out.println("Right angle");
	}
}